package cn.stylefeng.guns.modular.pandian.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.pandian.entity.PandianChoupan;
import cn.stylefeng.guns.modular.pandian.mapper.PandianChoupanMapper;
import cn.stylefeng.guns.modular.pandian.model.params.PandianChoupanParam;
import cn.stylefeng.guns.modular.pandian.model.result.PandianChoupanResult;
import  cn.stylefeng.guns.modular.pandian.service.PandianChoupanService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 抽盘表 服务实现类
 */
@Service
public class PandianChoupanServiceImpl extends ServiceImpl<PandianChoupanMapper, PandianChoupan> implements PandianChoupanService {

    @Override
    public void add(PandianChoupanParam param){
        PandianChoupan entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(PandianChoupanParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(PandianChoupanParam param){
        PandianChoupan oldEntity = getOldEntity(param);
        PandianChoupan newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public PandianChoupanResult findBySpec(PandianChoupanParam param,Long operateId){
        return this.baseMapper.findBySpec(param,operateId);
    }

    @Override
    public List<PandianChoupanResult> findListBySpec(PandianChoupanParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(PandianChoupanParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(PandianChoupanParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private PandianChoupan getOldEntity(PandianChoupanParam param) {
        return this.getById(getKey(param));
    }

    private PandianChoupan getEntity(PandianChoupanParam param) {
        PandianChoupan entity = new PandianChoupan();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
